package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.luo.model.Result;
import com.luo.model.SlideShow;
import com.luo.service.SlideShowsService;
import com.luo.util.ListTypes;
import org.aspectj.weaver.ast.Var;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/9 19:27
 */
@WebServlet(urlPatterns = "/home/banner")
public class SlideShowController extends HttpServlet {

    SlideShowsService slideShowsService = new SlideShowsService();

    @Override
    protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        String type = req.getParameter("distributionSite");
        List<SlideShow> slideShows = slideShowsService.queryTypeSlideShows(type);
        Result result = new Result();
        result.setCode("1");
        result.setMsg("查询成功");
        result.setResult(ListTypes.getObjList(slideShows));
        String jsonString = JSON.toJSONString(result);
        resp.getWriter().write(jsonString);
        resp.getWriter().close();
    }
}
